<template>
  <div class="register">
    <header>
      <span class="pre_span" @click="go()">&lt;</span>
      <span class="reg_span">注册</span>
      <span class="log_span" @click="go()">登录</span>
    </header>
    <div class="message_login">
      <div class="tel">
        <span>手机号:</span>
        <input type="text" v-model="name" @blur="getName" /><font>{{mesName}}</font>
      </div>
      <div class="pwd">
        <span>密码:</span>
        <input type="password" v-model="pwd" @blur="getPwd" /><font>{{mesPwd}}</font>
      </div>
      <div class="yznum">
        <span>验证码:</span>
        <input type="text" />
        <span class="get_yznum">点击获取</span>
      </div>
    </div>
    <div class="login_btn" @click="toLogin" @click.prevent>下一步</div>
    <div class="tips">
      <input type="checkbox" />
      <span>我已阅读并同意使用条款和隐私政策</span>
    </div>
  </div>
</template>

<script>
import * as types from '@/store/mutation-type'
export default {
  name: 'register',
  data () {
    return {
      name: '',
      pwd: '',
      mesName: '',
      mesPwd: ''
    }
  },
  methods: {
    go () {
      this.$router.go(-1)
    },
    goToReg (user) {
      this.$store.commit(types.ADD_USER, user)
    },
    getName () {
      if (!this.name) {
        this.mesName = '用户名不能为空'
      } else {
        this.mesName = ''
      }
    },
    getPwd () {
      var pat = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,14}$/
      if (!this.pwd) {
        this.mesPwd = '密码不能为空'
      } else if (!pat.test(this.pwd)) {
        this.mesPwd = '密码至少包含小写字母、大写字母和数字且长度不能低于六位'
      } else {
        this.mesPwd = ''
      }
    },
    toLogin () {
      if (!this.mesName && !this.mesPwd && !this.mesPwd2) {
        alert('注册成功')
        this.$router.push('/login')
      } else {
        alert('请按要求填写全部信息')
      }
    }
  }
}
</script>

<style lang="less" scoped>
header {
  height: 1.333333rem;
  line-height: 1.333333rem;
  width: 100%;
  background: #ff9900;
  text-align: center;
  font-size: 0.499867rem;
  color: #ffffff;
  .pre_span {
    position: absolute;
    left: 0.373333rem;
    font-size: 0.666667rem;
  }
  .log_span {
    position: absolute;
    right: 0.373333rem;
  }
}
.message_login {
  height: 5.6rem;
  margin: 0 0.933333rem;
  margin-top: 3.16rem;
  .tel,
  .pwd,
  .yznum {
    height: 1.773333rem;
    line-height: 1.773333rem;
    font-size: 0.4264rem;
    border-bottom: 1px solid #555555;
    overflow: hidden;
    font{
      font-size: .36rem;
      text-align: center;
      color: red;
    }
    span {
      display: block;
      width: 20%;
      float: left;
    }
    input {
      width: 45%;
      border: none;
      border-bottom: 1px solid #555555;
      float: left;
      height: 1.75rem;
      line-height: 1.76rem;
    }
  }
  .yznum {
    input {
      float: left;
    }
    .get_yznum {
      display: block;
      width: 35%;
      text-align: center;
      float: left;
      color: red;
    }
  }
  .forget {
    width: 100%;
    line-height: 1.36rem;
    font-size: 0.3732rem;
    position: relative;
    span {
      position: absolute;
      right: 0;
      color: #666666;
    }
  }
}
.login_btn {
  margin: 0 0.933333rem;
  height: 1.333333rem;
  line-height: 1.333333rem;
  text-align: center;
  font-size: 0.3732rem;
  background: #ff9900;
  color: #ffffff;
  border-radius: 0.133333rem;
}
.tips {
  margin: 0 0.933333rem;
  height: 1.333333rem;
  line-height: 1.333333rem;
  font-size: 0.35rem;
  position: relative;
  input {
    width: 0.4rem;
    height: 0.4rem;
    position: absolute;
    top: 0.5rem;
  }
  span {
    position: absolute;
    left: 0.65rem;
  }
}
</style>>
